﻿using System;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;
using Microsoft.Practices.EnterpriseLibrary.Logging;
using App.Core.Properties;

namespace App.Core.Logging
{
    /// <summary>
    /// Wrapper for system level logging
    /// </summary>
    public class AppLogger
    {
        #region Dependency Property
        private static bool _isDevelopmentEnvironment = true;
        public static bool IsDevelopmentEnvironment
        {
            get { return _isDevelopmentEnvironment; }
            set { _isDevelopmentEnvironment = value; }
            
        }
        #endregion
        /// <summary>
        /// Handles logging for general exception
        /// </summary>
        public static void LogException(Exception ex)
        {
            if (IsDevelopmentEnvironment)
                throw ex;

            ExceptionPolicy.HandleException(ex, EnterpriseLibraryResources.ExceptionPolicy_Default);            
        }
        /// <summary>
        /// Writes information event log
        /// </summary>
        public static void LogInfo(string message)
        {
            Logger.Write(message, EnterpriseLibraryResources.LoggingCategory_Info, 1, 1, System.Diagnostics.TraceEventType.Information);
        }
        /// <summary>
        /// Writes security log
        /// </summary>
        public static void LogSecurityInfo(string message)
        {
            Logger.Write(message, EnterpriseLibraryResources.LoggingCategory_Security, 5, 2, System.Diagnostics.TraceEventType.Critical);
        }
    }
}
